﻿Ext.define('app.system.substance.SubstanceController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.substance',
    init: function () {
        var me = this;
    },
    onAdd: function () {
        var grid = this.getView();
        var win = Ext.create("app.system.substance.Edit");
        win.on("savesuccess", function (obj) {
            win.close();
            grid.store.load();
        });
        win.show();
    },
    onEdit:  function (grid, rowIndex, colIndex) {
            var record = grid.store.getAt(rowIndex);
            var subId = record.get('id');
            //console.log(record);
            var win = Ext.create("app.system.substance.Edit", { subId: subId });
            win.on("savesuccess", function (obj) {
                win.close();
                grid.store.load();
            });
            win.show();


    },
    search:function(){
        
        var grid = this.getView();
        var keyword = grid.lookupReference("txt_Search").getValue();
        grid.store.filter = { keyword: keyword };
        grid.store.load();
    }
});
